package com.jason.order.config.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import io.seata.core.context.RootContext;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

/**
 * feign请求中增加XID
 */
@Configuration
public class FeignConfiguration implements RequestInterceptor {
    private static final Logger logger = LoggerFactory.getLogger(FeignConfiguration.class);

    @Override
    public void apply(RequestTemplate template) {
        String xid = RootContext.getXID();
        if (StringUtils.isNotEmpty(xid)) {
            template.header(RootContext.KEY_XID, xid);
        }
        logger.info("feign interceptor header:{}",template);
    }
}
